<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 核心算法，遍历旧数组，拿着旧数组元素查询新数组，不重复则添加到新数组中
        // 利用indexOf(数组元素),返回-1则说明新数组里没有该元素
        var arr0 = ['a', 'a', 'b', 'c', 'z', 'a', 'x', 'b']
        function unique(arr) {
            var newArr = [];
            for (var i = 0; i < arr.length; i++) {
                if (newArr.indexOf(arr[i]) === -1) {
                    newArr.push(arr[i]);
                }

            }
            return newArr;
        }
        console.log(unique(arr0));
    </script>
</head>

<body>

</body>

</html>